<template>
	<view class="mainbgc">
		<header-top :messageInfo="{typeFlag:true,message:'收款历史',liner:false}">
		</header-top>
		<view class="mainpadding_nobot">
			<view class="flexbetween">
				<view class="yuangbox flexleft">
					<view class="ygtext">员工：</view>
					<view :class="staff_name?'lansebtn allbtn':'allbtn huisebtn'"
						@click="selectRole('/pages/workbench/jiben/yuangongda?type=2')">
						{{staff_name || '选择员工'}}
					</view>
				</view>
				<view class="ygtext" @click="sxshow=true">选择日期</view>
			</view>
		</view>
		<view class="" style="padding-bottom: 150rpx;">
			<view class="" v-for="item in dataAll.staffdata" :key="item.staff_id">
				<view class="flexleft mainpadding">
					<view class="duiztitle">{{item.staff.username}}</view>
					<view class="chexiao" style="margin-left: 40rpx;" @click.stop="chexiao(item.staff_id,'',128)">撤销</view>
				</view>
				<view class="bgcs ffffff">
					<view class="kuantiaos mainpadding" v-for="ite in item.skdzlist" :key="ite.id">
						<view class="flexbetween">
							<view class="flexleft" style="align-items: flex-start;">
								<!-- :1=销售单.2=预收款,3=客户结算 -->
								<view class="time-text" v-show="ite.type==1">销售单:</view>
								<view class="time-text" v-show="ite.type==2">预收款:</view>
								<view class="time-text" v-show="ite.type==3">客户结算:</view>
								<view class="time-text">{{ite.createtime_text}}</view>
								<view class="chexiao" style="margin-left: 40rpx;" @click.stop="chexiao('',ite.id,128)">撤销</view>
							</view>
							<view class="qianshu-text">{{ite.price}}</view>
						</view>
						<view class="time-text">备注:{{ite.notes}}</view>
					</view>
				</view>
			</view>
		</view>
		
	    <view class=" ffffff bottombox" >
	    	<view class="daijiaoje" style="text-align: right;">
	    		合计：￥{{dataAll.total_price}}
	    	</view>
	    </view>
		<u-popup round="20" :show="sxshow" @close="sxshow=false">
			<view class="mainpadding">
				<view class="flexcenter">
					<view class="titletext">筛选</view>
				</view>
				<view class="strongtext margin_top">时间</view>
				<view class="flexleft" style="flex-wrap: wrap;">
					<view class="screenbox flexcenter" v-for="(item,index) in datelist" :key="item.id"
						@click="change(item.name,index)">
						<view :class="currents == index? 'itemscreenfocus margin_top':'itemscreen margin_top'">
							{{item.name}}
						</view>
					</view>
				</view>
				<view class="strongtext margin_top">自定义时间</view>
				<view class="flexleft">
					<view class="inputscreenbox flexcenter" @click="shows=true">
						<input class="itemscreen margin_top" type="text" disabled v-model="start">
					</view>
					<view class="zwscreenbox flexcenter">
						<view class="strongtext">-</view>
					</view>
					<view class="inputscreenbox flexcenter" @click="showss=true">
						<input class="itemscreen margin_top" type="text" disabled v-model="end">
					</view>
				</view>
				<view class="flexbetween">
					<view class="surebtn reset flexcenter" style="margin-top: 60rpx;" @click="resetbtn">重置</view>
					<view class="surebtn flexcenter" style="margin-top: 60rpx;" @click="sureBtn">确认</view>
				</view>
			</view>
		</u-popup>
		<u-datetime-picker :show="shows" v-model="value1" mode="date" @confirm="confirm" @cancel="shows=false"
			 @close="shows=false"></u-datetime-picker>
		<u-datetime-picker :show="showss" v-model="value2" mode="date" @confirm="confirms" @cancel="showss=false"
			:minDate="mintime" @close="showss=false"></u-datetime-picker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				// 日期筛选
				sxshow: false,
				currents: -1,
				start: '开始时间',
				end: '结束时间',
				shows: false,
				showss: false,
				value1: Number(new Date()),
				value2: Number(new Date()),
				mintime: Number(new Date()),
				datelist: [{
						id: 1,
						name: '今日'
					},
					{
						id: 2,
						name: '昨日'
					},
					{
						id: 3,
						name: '本月'
					},
				],
				staff_name:"",
				staff_id:"",
				dataAll:{}
			}
		},
		onLoad() {
			uni.hideTabBar(); //隐藏tab
		},
		onShow() {
			uni.$off('ygSelectFn');
			uni.$on('ygSelectFn', (data) => {
				this.staff_id = data.id
				this.staff_name = data.name
			})
			this.init()
		},
		methods: {
			selectRole(url) {
				uni.navigateTo({
					url
				})
			},
			init() {
				httpRequest.request('/dhtapi/user/skdzIndex', 'POST', {
					start_time: this.start == "开始时间" ? "" : this.start,
					end_time: this.end == "结束时间" ? "" : this.end,
					staff_id: this.staff_id
				}).then(res => {
					if (res.code == 1) {
						this.dataAll = res.data
					} else {
						httpRequest.toast(res.msg)
					}
				}).catch(err => {
					httpRequest.toast(err.msg)
				})
			},
			// 撤销
			chexiao(id1,id2,qxpdid) {
				if (!httpRequest.qxpd(qxpdid, this.$store.state.userInfo.ability_rule_ids)) {
					return false
				}
				httpRequest.request('/dhtapi/user/cxSkdz', 'POST', {
					id:id2,
					staff_id:id1
				}).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.init()
					}
				}).catch(err => {
					httpRequest.toast(err.msg)
				})
			},
			jumpdetail(id){
				uni.navigateTo({
					url:"/pages/workbench/caiwu/shoukuanlsxq?id=" + id
				})
			},
			// 员工档案确定
			yuangongSure(e) {
				this.yuangongShow = false
				if (e) {
					this.yuangong.id = e.value[0].id
					this.yuangong.name = e.value[0].name
					this.init()
				}
			},
			confirm(e) {
				console.log(e);
				this.shows = false;
				this.show = true;
				this.end = '结束时间';
				this.mintime = e.value;
				this.start = this.date(e.value);
				this.currents = -1;
			},
			confirms(e) {
				this.showss = false;
				this.show = true;
				this.maxtime = e.value;
				this.end = this.date(e.value);
				this.currents = -1;
			},
			date(timer) {
				var date = new Date(timer); //当前时间
				var year = date.getFullYear() //返回指定日期的年份
				var month = repair(date.getMonth() + 1); //月
				var day = repair(date.getDate()); //日
				var curTime = year + "-" + month + "-" + day
			
				function repair(i) {
					if (i >= 0 && i <= 9) {
						return "0" + i;
					} else {
						return i;
					}
				}
				return curTime
			},
			change(name, index) {
				if (name == "今日") {
					this.start = this.riqi(0);
					this.end = this.riqi(0);
				} else if (name == "昨日") {
					this.start = this.riqi(-1);
					this.end = this.riqi(-1);
				} else if (name == "本月") {
					this.start = this.benyue();
					this.end = this.riqi(0);
				}
				this.currents = index;
			},
			// 昨天“-1”今天“0”明天“1”
			riqi(day) {
				let dd = new Date();
				dd.setDate(dd.getDate() + day);
				let y = dd.getFullYear();
				let m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
				let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
				return y + "-" + m + "-" + d;
			},
			// 本月第一天
			benyue() {
				let y = new Date().getFullYear(); //获取年份
				let m = new Date().getMonth() + 1; //获取月份
				let d = '01'
				m = m < 10 ? '0' + m : m; //月份补 0
				return [y, m, d].join("-")
			},
			sureBtn() {
				this.sxshow = false
				this.init()
			},
			// 重置
			resetbtn() {
				this.currents = -1
				this.start = "开始时间"
				this.end = "结束时间"
				this.init()
				this.sxshow = false
			},
		}
	}
</script>

<style lang="scss" scoped>
	.kuantiaos{
		border-bottom: 1rpx solid rgba(0, 0, 0, 0.02);
	}
	.qianshu-text{
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #0BBDCB;
		margin-right: 16rpx;
	}
	.time-text{
		font-size: 22rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: 500;
		color: rgba(153, 153, 153, 1);
	}
	.riqi-text{
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #000000;
	}
	.chexiao{
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
	}
	.bottombox{
		padding: 38rpx 30rpx 80rpx;
		position: fixed;
		width: 100%;
		bottom: 0;
		left: 0;
		box-sizing: border-box;
	}
	.daijiaoje{
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
	}
	.shangjiaobtn{
		background: linear-gradient(273deg, #0BBDCB 0%, #41D4E2 100%);
		border-radius: 41rpx 41rpx 41rpx 41rpx;
		padding: 12rpx 44rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}
	.duiztitle {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	// .bgcs{
	// 	padding-bottom: 200rpx;
	// }
	.dingdqian {
		margin-left: 156rpx;
	}

	.righticon2 {
		width: 13rpx;
		height: 20rpx;
		image {
			width: 100%;
			height: 100%;
		}
	}

	.alltext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.qianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #0BBDCB;
	}

	.daijiao {
		font-size: 22rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #F3AD3D;
		margin-left: 40rpx;
	}

	.xiaoshou {
		font-size: 30rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #000000;
	}

	.shoukuaant {
		padding: 30rpx 30rpx 20rpx;
		border-bottom: 1rpx solid rgba(0, 0, 0, .02);
	}

	.img {
		width: 40rpx;
		height: 40rpx;
	}

	.oneimg {
		margin-right: 12rpx;
	}

	// tab切换
	.selectbox {
		padding: 6rpx 30rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #0BBDCB;
		line-height: 33rpx;
		background-color: #e1f4f5;
		border-radius: 30rpx;
		margin-right: 30rpx;
	}

	.noselectbox {
		padding: 6rpx 30rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #999999;
		line-height: 33rpx;
		background-color: #eff0f0;
		border-radius: 30rpx;
		margin-right: 30rpx;
	}

	.selecttimetext {
		font-size: 24rpx;
		font-family: San Francisco Display-Medium, San Francisco Display;
		font-weight: 500;
		color: #666666;
		line-height: 24rpx;
	}

	.yuangbox {
		display: flex;
		align-items: center;
	}

	.ygbtn {
		margin: 16rpx 0 22rpx;
		background: rgba(153, 153, 153, .1);
		border-radius: 50rpx 50rpx 50rpx 50rpx;
		padding: 14rpx 120rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}
	.screenbox {
		width: 33.33%;
	}
	
	.itemscreenfocus {
		width: 200rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 50rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
		background-color: #e7f9fa;
	}
	.ygtext{
		color: #666;
		font-weight: bold;
		font-size: 32rpx
	}
	
	.inputscreenbox {
		width: 40%;
	
		input {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			border-radius: 50rpx;
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #333;
			background-color: #f7f9fa;
		}
	}
	
	.itemscreen {
		width: 200rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 50rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		background-color: #f7f9fa;
	}
	
	.zwscreenbox {
		width: 20%;
		line-height: 80rpx;
	}
	
	// 选择框
	.itemscreens {
		padding-bottom: 20rpx;
	}
	
	.rightscreen {
		width: 100%;
	}
	
	.right {
		width: 100%;
	}
	
	.minwidth {
		min-width: 130rpx;
	}
	
	.surebtn {
		width: 45%;
	}
	
	.reset {
		background: #ebb563;
	}
	.allbtn {
		width: 350rpx;
		height: 52rpx;
		border-radius: 50rpx;
		font-size: 24rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}
	
	.lansebtn {
		color: #0BBDCB;
		background: rgba(11, 189, 203, .1);
	}
	
	.huisebtn {
		color: #999999;
		background: rgba(153, 153, 153, .1);
	}
	.mainpadding_nobot{
		padding: 30rpx 30rpx 0 30rpx;
	}
</style>
